# 项目名称，生成静态库
PROJECT = libboundscheck.a

# 交叉编译器工具链
CC  ?= arm-none-eabi-gcc
AR  ?= arm-none-eabi-ar
RM  ?= rm -rf
MKDIR ?= mkdir -p

# MCU 架构相关参数（根据实际芯片型号调整）
MCU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard

# 编译选项
CFLAGS  = -Wall -DNDEBUG -O2 $(MCU_FLAGS) -Iinclude

# 源文件和目标文件
SOURCES = $(wildcard src/*.c)
OBJECTS = $(patsubst src/%.c, obj/%.o, $(SOURCES))

# 伪目标
.PHONY: all clean

# 默认目标
all: lib/$(PROJECT)
	@echo "Build finish: lib/$(PROJECT)"

# 生成静态库
lib/$(PROJECT): $(OBJECTS)
	$(MKDIR) lib
	$(AR) rcs $@ $^

# 编译每个源文件
obj/%.o: src/%.c
	$(MKDIR) obj
	$(CC) -c $< $(CFLAGS) -o $@

# 清理
clean:
	$(RM) obj lib
	@echo "clean up"
